//单位转换：字节 转 KB、MB、GB
export default {
    size2Str: (limit) => {
        var size = "";
        if (limit < 0.1 * 1024) {
            size = limit.toFixed(2) + "B"           //小于0.1KB，则转化成B   （toFixed(2)方法用于将数字格式化为保留两位小数的字符串）
        } else if (limit < 0.1 * 1024 * 1024) {
            size = (limit / 1024).toFixed(2) + "KB"     //小于0.1MB，则转化成KB
        } else if (limit < 0.1 * 1024 * 1024 * 1024) {
            size = (limit / (1024 * 1024)).toFixed(2) + "MB"  //小于0.1GB，则转化成MB
        } else {
            size = (limit / (1024 * 1024 * 1024)).toFixed(2) + "GB"  //转化为GB
        }
        var sizeStr = size + "";                //转化成字符串
        var index = sizeStr.indexOf(".");       //获得小数点处的索引
        var dou = sizeStr.substr(index + 1, 2); //获取小数点后两位
        if (dou == "00") {                      //判断小数点后两位数是否为00，是则删除00
            return sizeStr.substring(0, index) + sizeStr.substr(index + 3, 2);
        }
        return size;
    }
} 